package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.basedoc.model.PersonalInfo;
import com.eling.elcms.community.model.Organization;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.member.model.Member;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 客户
 * @author zhoulin 模型评审：需要根据最新的产品类型模型调整模型，wulina 2016-09-07
 */
@Entity
@Indexed
@Table(name = "travel_customer")
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class),
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "organization:organization") })
public class Customer extends BaseModel {

	private static final long serialVersionUID = -6948428180878847217L;

	@Id
	@In
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkCustomer;

	/** 所属机构 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganization")
	@IndexedEmbedded(depth = 1)
	@In
	private Organization organization;

	/** 人员信息 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkPersonalInfo")
	@IndexedEmbedded(depth = 1)
	private PersonalInfo personalInfo;

	/** 产品类型 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkProductType")
	@IndexedEmbedded(depth = 1)
	@In
	private ProductType productType;

	/** 销售顾问 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkSaleConsultant")
	@IndexedEmbedded(depth = 1)
	private CommonUser saleConsultant;

	/** QQ */
	@Column
	@Field
	private String qq;

	/** 微信 */
	@Column
	@Field
	private String wechat;

	/** 邮编 */
	@Column
	@Field
	private String zipCode;

	/** 来访次数 */
	@Column
	@Field
	private Integer visitCount;

	/** 最新来访时间 */
	@Column
	@Field
	@Between
	private Date visitTime;

	/** 回访次数 */
	@Column
	@Field
	private Integer returnVisitCount;

	/** 最新回访时间 */
	@Column
	@Field
	@Between
	private Date returnVisitTime;

	/** 最新意向 */
	@Enumerated(EnumType.STRING)
	@FieldBridge(impl = EnumBridge.class)
	@Field
	private Intention intention;

	/** 状态 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private Status status;

	/** 转换成会员 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkMember")
	@IndexedEmbedded(depth = 1)
	private Member member;

	/** 客户数据来源（来访/报名） */
	@Enumerated(EnumType.STRING)
	@Field
	@In
	@FieldBridge(impl = EnumBridge.class)
	private DataSource dataSource;

	/** 是否转会员 */
	private Boolean transMember;

	@Version
	private Integer version;

	@JsonSerialize(using = EnumSerializer.class)
	public enum Status {
		NoIntention("无意向"),Intention("意向中"), Contract("已签约");

		private String display;

		Status(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	@JsonSerialize(using = EnumSerializer.class)
	public static enum DataSource {
		NoMember("散客"),Visit("来访"), SignUp("报名"), Alliance("联盟团");

		private String display;

		DataSource(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkCustomer() {
		return pkCustomer;
	}

	public void setPkCustomer(Long pkCustomer) {
		this.pkCustomer = pkCustomer;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public PersonalInfo getPersonalInfo() {
		return personalInfo;
	}

	public void setPersonalInfo(PersonalInfo personalInfo) {
		this.personalInfo = personalInfo;
	}

	public ProductType getProductType() {
		return productType;
	}

	public void setProductType(ProductType productType) {
		this.productType = productType;
	}

	public CommonUser getSaleConsultant() {
		return saleConsultant;
	}

	public void setSaleConsultant(CommonUser saleConsultant) {
		this.saleConsultant = saleConsultant;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getWechat() {
		return wechat;
	}

	public void setWechat(String wechat) {
		this.wechat = wechat;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public Integer getVisitCount() {
		return visitCount;
	}

	public void setVisitCount(Integer visitCount) {
		this.visitCount = visitCount;
	}

	public Date getVisitTime() {
		return visitTime;
	}

	public void setVisitTime(Date visitTime) {
		this.visitTime = visitTime;
	}

	public Integer getReturnVisitCount() {
		return returnVisitCount;
	}

	public void setReturnVisitCount(Integer returnVisitCount) {
		this.returnVisitCount = returnVisitCount;
	}

	public Date getReturnVisitTime() {
		return returnVisitTime;
	}

	public void setReturnVisitTime(Date returnVisitTime) {
		this.returnVisitTime = returnVisitTime;
	}

	public Intention getIntention() {
		return intention;
	}

	public void setIntention(Intention intention) {
		this.intention = intention;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public Boolean getTransMember() {
		return transMember;
	}

	public void setTransMember(Boolean transMember) {
		this.transMember = transMember;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

}
